# frozen_string_literal: true

class RuleOutput
  class Dsl < RuleOutput
    has_one :formula, as: :formulable, dependent: :destroy

    delegate :fire, to: :formula

    def deep_clone_to_draft
      output = super
      output.create_formula! formula.slice(:type, :content)
      output
    end

    def deep_update(params)
      if params[:type].eql?(self.class.name)
        formula.update! params.require(:formula).slice(:type, :content)
      else
        formula.destroy!
      end

      super
    end

    def validate(_variable_type)
      # raise 'Unsupported.'
    end
  end
end
